<?php
require_once BaseUtil::getModulePath("base") . '/controllers/BaseController.php';
require_once BaseUtil::getModulePath("order") . '/services/OrderService.php';
require_once BaseUtil::getModulePath("trade") . '/services/TradeComponentService.php';
require_once BaseUtil::getModulePath("order") . '/constants/OrderConstant.php';
require_once BaseUtil::getModulePath("order") . '/constants/StateConstant.php';
require_once BaseUtil::getModulePath("acl") . '/services/AdminService.php';

require_once BaseUtil::getModulePath("systemlog") . '/services/EmailService.php';

class Order_OrderController extends BaseController
{
    public function init ()
    {
        parent::init();
        $this->view->script = array(
            'lib/ui.dialog.js' , 
            'order.js'
        );
    }
    public function indexAction ()
    {
        $orderService = new OrderService();
        $list = $orderService->getOrders($this->view, $_POST);
        $this->view->dbGrid = $list;
    }
    public function editAction ()
    {
        $list = $this->getOptionList();
        $orderId = $this->_getParam("id");
        $order = array();
        $edit = 'false';
        $nextString = '';
        if (! empty($orderId)) {
            $orderService = new OrderService();
            $order = $orderService->getOrderById($orderId);
            $items = $orderService->getOrderItemsById($orderId);
            if($order['is_returned']=='1'){
                $this->_redirector->gotoUrl('/order/order/detail/id/'.$order['id']);
            }
        } else {              
            $this->_redirector->gotoUrl('/order/order');
        }
        
        switch ($order['status']) {
            case 1:
                $edit = "false";
                $nextString = 'pCloseBtn';
                break;
            case 2:
                $edit = "true";
                break;
            case 3:
                $edit = 'true';
                $nextString = 'sendBtn';
                break;
            case 4:
                $edit = "false";
                $nextString = 'pSuccess';
                break;
            case 5:
                $edit = "false";
                break;
            case 6:
            case 7:
                // $newStatus = 7;
                break;
            case 11:
                $nextString = 'uCloseBtn';
                $edit = "false";
                break;
            case 12:
                $nextString = 'uSendBtn';
                $edit = "true";
                break;
            case 13:
                $nextString = 'uSuccess';
                break;
            case 14:
                 $nextString = 'uReceive';
               
                $edit = "false";
                break;
            case 15:
                $edit = "false";
                break;
            case 16:
            case 17:
                // $newStatus = 17;
                break;
            case 21:
                $nextString = 'aCloseBtn';
                $edit = "false";
                break;
            case 22:
                $nextString = 'aSendBtn';
                $edit = 'true';
                break;
            case 24:
               $nextString = 'aReceive';
                $edit = "false";
                break;
            case 23:
                 $nextString = 'aSuccess';
                
                $edit = "false";
                break;
            case 25:
                $edit = "false";
                break;
            case 26:
            case 27:
                // $newStatus = 27;
                break;
            default:
            // $newStatus = 0;
        }
        $adminService = new AdminService();
        $admins = $adminService->getAllAdmins();
        
        $this->view->edit = $edit;
        $this->view->nextString = $nextString;
        $this->view->order = $order;
        $this->view->items = $items;
        $this->view->status = $list['status'];
        $this->view->shipping = $list['shipping'];
        $this->view->method = $list['method'];
        $this->view->state = $list['state'];
        $this->view->admins = $admins;
    }
    public function itemspanelAction ()
    {
        $this->_helper->layout->disableLayout();
        $orderId = $this->_getParam("id");
        $edit = $_POST['edit'];
        $orderService = new OrderService();
        $items = $orderService->getOrderItemsById($orderId);
        $packages = $orderService->getPackagesById($orderId);
        $packagesArray = array();
        foreach ($packages as $package) {
            $results = $orderService->getItemsByPackageId($package['id']);
            $packageItems = array();
            foreach ($results as $result) {
                $packageItems[$result['order_item_id']] = $result;
            }
            $packagesArray[$package['id']] = $packageItems;
        }
        $this->view->items = $items;
        $this->view->orderId = $orderId;
        $this->view->packages = $packages;
        $this->view->packagesItems = $packagesArray;
        $this->view->edit = $edit;
    }
    public function subpackageAction ()
    {
        $this->_helper->layout->disableLayout();
        $orderId = HttpUtil::getPostString('orderid');
        $id = HttpUtil::getPostString('orderitemid');
        if (! empty($id)) {
            $ids = explode(",", $id);
            $orderService = new OrderService();
            $results = $orderService->getPackageItemsById($ids, $orderId);
        }
        $this->view->results = $results;
        $this->view->id = $orderId;
    }
    public function addAction ()
    {
        $list = $this->getOptionList();
        $this->view->status = $list['status'];
        $this->view->shipping = $list['shipping'];
        $this->view->method = $list['method'];
        $this->view->state = $list['state'];
    }
    public function processAction ()
    {
        $id = $this->_getParam('id');
        $orderService = new OrderService();
        $order = $orderService->getOrderById($id);
        $this->view->order = $order;
    }
    public function deleteAction ()
    {}
    public function getitemsAction ()
    {
        $this->_helper->layout->disableLayout();
        $id = $this->_getParam('id');
        $orderService = new OrderService();
        $items = $orderService->getOrderItemsById($id);
        $packages = $orderService->getPackagesById($id);
        $this->view->items = $items;
        $this->view->packages = $packages;
        $this->view->id = $id;
    }
    //    public function subpackageAction() {
    //        $this->_helper->layout->disableLayout();
    //        $orderId=HttpUtil::getPostString('orderid');
    //        $id=HttpUtil::getPostString('orderitemid');
    //        if(!empty($id)) {
    //            $ids = explode(",", $id);
    //            $orderService=new OrderService();
    //            $results=$orderService->getPackageItemsById($ids,$orderId);
    //        }
    //        $this->view->results=$results;
    //        $this->view->id = $orderId;
    //    }
    public function addpackageAction ()
    {
        $package = array();
        $package['tracking_num'] = HttpUtil::getPostString('trackNumber');
        $package['package_num'] = Number::getPackageNumber();
        $package['status'] = HttpUtil::getPostString('status');
        $package['order_id'] = HttpUtil::getPostString('orderId');
        $package['shipping_method_id'] = HttpUtil::getPostString('shippingMethod');
        $ids = HttpUtil::getPostValue('id');
        $qtys = HttpUtil::getPostValue('qty');
        $items = $this->createPackageItemsSet($ids, "order_item_id", $qtys);
        if (! empty($items)) {
            $orderService = new OrderService();
            $orderService->addPackage($package, $items);
        }
        exit();
    }
    public function cancelitemAction ()
    {
        $this->_helper->layout->disableLayout();
        $id = HttpUtil::getPostString('id');
        //if(!empty($id)){
        //	$orderService = new OrderService();
        //}
        $this->view->id = $id;
    }
    public function subcancelAction ()
    {
        $id = HttpUtil::getPostString('id');
        $note = HttpUtil::getPostString('note');
        if (! empty($id)) {
            $cancelItem = array();
            $cancelItem['status'] = 1;
            $cancelItem['note'] = $note;
            $orderService = new OrderService();
            $orderService->cancelOrderItem($id, $cancelItem);
        }
        exit();
    }
    public function editpackageAction ()
    {
        $this->_helper->layout->disableLayout();
        $id = HttpUtil::getPostString('id');
        if (! empty($id)) {
            $orderService = new OrderService();
            $package = $orderService->getPackageById($id);
            $items = $orderService->getItemsByPackageId($id);
        }
        $this->view->package = $package;
        $this->view->items = $items;
        $this->view->id = $id;
    }
    public function updatepackageAction ()
    {
        $pid = HttpUtil::getPostString('pid');
        $package = array();
        $package['package_num'] = Number::getPackageNumber();
        $package['tracking_num'] = HttpUtil::getPostString('trackNumber');
        $package['status'] = HttpUtil::getPostString('status');
        $package['order_id'] = HttpUtil::getPostString('orderId');
        $package['shipping_method_id'] = HttpUtil::getPostString('shippingMethod');
        $ids = HttpUtil::getPostValue('id');
        $qtys = HttpUtil::getPostValue('qty');
        $items = $this->createPackageItemsSet($ids, "id", $qtys);
        if (! empty($items)) {
            $orderService = new OrderService();
            $orderService->editPackage($pid, $package, $items);
        }
        exit();
    }
    public function delpackageAction ()
    {
        $id = HttpUtil::getPostString('id');
        $orderService = new OrderService();
        $orderService->delPackage($id);
        exit();
    }
    private function createPackageItemsSet ($ids, $idName, $qtys)
    {
        $items = array();
        if (is_array($ids) && is_array($qtys)) {
            foreach ($ids as $key => $id) {
                $items[$key][$idName] = $id;
                $items[$key]['quantity'] = $qtys[$key];
            }
        }
        return $items;
    }
    public function subaddAction ()
    {
        //address info
        $shippingAddress = array();
        $shippingAddress['first_name'] = HttpUtil::getPostString("sfirstname");
        $shippingAddress['last_name'] = HttpUtil::getPostString("slastname");
        $shippingAddress['address1'] = HttpUtil::getPostString("saddress1");
        $shippingAddress['address2'] = HttpUtil::getPostString("saddress2");
        $shippingAddress['city'] = HttpUtil::getPostString("scity");
        $shippingAddress['state'] = HttpUtil::getPostString("sstate");
        $shippingAddress['zip_code'] = HttpUtil::getPostString("szipcode");
        $shippingAddress['phone'] = HttpUtil::getPostString("sphone");
        $billingAddress = array();
        if (isset($_POST['sameAsSAddress']) && $_POST['sameAsSAddress'] == 1) {
            $billingAddress = $shippingAddress;
        } else {
            $billingAddress['first_name'] = HttpUtil::getPostString("bfirstname");
            $billingAddress['last_name'] = HttpUtil::getPostString("blastname");
            $billingAddress['address1'] = HttpUtil::getPostString("baddress1");
            $billingAddress['address2'] = HttpUtil::getPostString("baddress2");
            $billingAddress['city'] = HttpUtil::getPostString("bcity");
            $billingAddress['state'] = HttpUtil::getPostString("bstate");
            $billingAddress['zip_code'] = HttpUtil::getPostString("bzipcode");
            $billingAddress['phone'] = HttpUtil::getPostString("bphone");
        }
        //order info
        $orderNum = Number::getOrderNumber();
        $order = array(
            "order_num" => $orderNum , 
            "customer_id" => HttpUtil::getPostValue('customerid') , 
            "status" => HttpUtil::getPostValue('status') , 
            "shipping_expect" => HttpUtil::getPostValue('shipping') , 
            "payment_method" => HttpUtil::getPostValue('method')
        );
        $itemIds = HttpUtil::getPostValue("itemid");
        $orderService = new OrderService();
        $orderService->addOrder($shippingAddress, $billingAddress, $order, $itemIds);
        $this->_redirector->gotoUrl('/order/order');
    }
    //    public function editAction() {
    //        $list = $this->getOptionList();
    //        $orderId = $this->_getParam("id");
    //        $order = array();
    //        if(!empty($orderId)) {
    //            $orderService = new OrderService();
    //            $order = $orderService->getOrderAllById($orderId);
    //            $items = $orderService->getOrderItemsById($orderId);
    //        }
    //        $this->view->order = $order;
    //        $this->view->items = $items;
    //        $this->view->status = $list['status'];
    //        $this->view->shipping=$list['shipping'];
    //        $this->view->method=$list['method'];
    //        $this->view->state=$list['state'];
    //    }
    public function subeditAction ()
    {
        //print_r($_POST);
        $orderId = $_POST['orderId'];
        $orderService = new OrderService();
        $order = $orderService->getOrderById($orderId);
        $tradeComponentService = new TradeComponentService();
        $newOrder = array();
        
        //发邮件确认
        $emailService = new EmailService();
        //邮件主体
        $this->addLocaleData("emaillog");
        $shippedInformEmail = $this->_translate->translate("shippedInformEmail");
        $successEmailTitle = $this->_translate->translate("orderSuccessInformEmail");
        $orderConfirmEmailTitle = $this->_translate->translate("orderConfirmInformEmail");
        $param = array("orderId" => $orderId , "successEmailTitle" => $successEmailTitle, "shippedInformEmail" => $shippedInformEmail, "orderConfirmEmailTitle" => $orderConfirmEmailTitle);
        
        
        switch ($_POST['nextString']) {
            case 'pSuccess':
                $newOrder['status'] = 5;
                break;
            case 'sendBtn':
                $newOrder['status'] = 4;
                break;
            case 'uSendBtn':
                $newOrder['status'] = 14;
                $refund = $order["total"];
                $ship_profit_total = $order["ship_profit_total"];
                $order_profit_total = $order["order_profit_total"];
                if ($tradeComponentService->checkoutMoney($order['agent_id'], $refund, 32, $order['order_num'] ,$orderId, 0)) {
                    if ($order_profit_total > 0) {
                    	$userIdTemp = $orderService->getAgentId($order['user_id']);
                        $tradeComponentService->addProfit($userIdTemp, $order_profit_total, 34, $orderId, $order['order_num'], 0);
                    }
                    if ($ship_profit_total > 0) {
                        $tradeComponentService->addProfit($order['agent_id'], $ship_profit_total, 34, $orderId, $order['order_num'], 0);
                    }
                    //add user point
                    $tradeComponentService->updateUserPoint($order['user_id'],$order['total'],$order['order_num']);
                    
                    //已发货
                $emailService->sendedGoogsEmailToUser($param);

                }
                break;
            case 'aSendBtn':
                $newOrder['status'] = 24;
                $refund = $order["total"];
                $ship_profit_total = $order["ship_profit_total"];
                $order_profit_total = $order["order_profit_total"];
                if ($tradeComponentService->checkoutMoney($order['agent_id'], $refund, 32, $order['order_num'],$orderId, 0)) {
                    if ($order_profit_total > 0) {
                        $tradeComponentService->addProfit($order['user_id'], $order_profit_total, 34, $orderId, $order['order_num'], 0);
                    }
                    if ($ship_profit_total > 0) {
                        $tradeComponentService->addProfit($order['agent_id'], $ship_profit_total, 34, $orderId, $order['order_num'], 0);
                    }
                    //add user point
                    $tradeComponentService->updateUserPoint($order['user_id'],$order['total'],$order['order_num']);                    
                }
                break;
            case 'uSuccess':
                $newOrder['status'] = 15;
                
                //交易成功发邮件
                $emailService->orderSuccessEmailToUser($param);

                break;
            case 'aSuccess':
                $newOrder['status'] = 25;
                break;
            case 'uReceive':
                $newOrder['status'] = 13;
                break;
            case 'aReceive':
                $newOrder['status'] = 23;
                break;
            case 'pCloseBtn':
                $newOrder['status'] = 6;
                break;
            case 'uCloseBtn':
                $newOrder['status'] = 16;
                break;
            case 'aCloseBtn':
                $newOrder['status'] = 26;
                break;
            case 'confirmOrderBtn':
                if($order["status"]==11){
                	 //发订单确认信
                	 $emailService->orderConfirmationEmailToUser($param);
                     $newOrder['status'] = 12;
                }else if($order["status"]==21){
                     $newOrder['status'] = 22;
                }
                  break;
        }
        $orderService->updateOrder($_POST['orderId'], $newOrder);
        if($newOrder['status'] == 6 || $newOrder['status'] == 16 || $newOrder['status'] == 26){
        	$orderService->returnInventoryByOrderId($orderId);
        }
        
        //echo 'ok';exit;
        //order info
        //        $orderId = HttpUtil::getPostString("orderId");
        //        $order = array();
        //        $order['customer_id'] = HttpUtil::getPostValue('customerid');
        //        $order['status'] = HttpUtil::getPostValue('status');
        //        $order['shipping_expect'] = HttpUtil::getPostValue('shipping');
        //        $order['payment_method'] = HttpUtil::getPostValue('method');
        //        //shipping address
        //        $sid = HttpUtil::getPostString("sid");
        //        $shippingAddress = array();
        //        $shippingAddress['first_name'] = HttpUtil::getPostString("sfirstname");
        //        $shippingAddress['last_name'] = HttpUtil::getPostString("slastname");
        //        $shippingAddress['address1'] = HttpUtil::getPostString("saddress1");
        //        $shippingAddress['address2'] = HttpUtil::getPostString("saddress2");
        //        $shippingAddress['city'] = HttpUtil::getPostString("scity");
        //        $shippingAddress['state'] = HttpUtil::getPostString("sstate");
        //        $shippingAddress['zip_code'] = HttpUtil::getPostString("szipcode");
        //        $shippingAddress['phone'] = HttpUtil::getPostString("sphone");
        //        //billing address
        //        $bid = HttpUtil::getPostString("bid");
        //        $billingAddress = array();
        //        if (isset($_POST['sameAsSAddress']) && $_POST['sameAsSAddress'] == 1) {
        //            $billingAddress = $shippingAddress;
        //        } else {
        //            $billingAddress['first_name'] = HttpUtil::getPostString("bfirstname");
        //            $billingAddress['last_name'] = HttpUtil::getPostString("blastname");
        //            $billingAddress['address1'] = HttpUtil::getPostString("baddress1");
        //            $billingAddress['address2'] = HttpUtil::getPostString("baddress2");
        //            $billingAddress['city'] = HttpUtil::getPostString("bcity");
        //            $billingAddress['state'] = HttpUtil::getPostString("bstate");
        //            $billingAddress['zip_code'] = HttpUtil::getPostString("bzipcode");
        //            $billingAddress['phone'] = HttpUtil::getPostString("bphone");
        //        }
        //        //item info
        //        $itemIds = HttpUtil::getPostValue("itemid");
        //        $orderAll = array();
        //        $orderAll['orderId'] = $orderId;
        //        $orderAll['order'] = $order;
        //        $orderAll['sid'] = $sid;
        //        $orderAll['shippingAddress'] = $shippingAddress;
        //        $orderAll['bid'] = $bid;
        //        $orderAll['billingAddress'] = $billingAddress;
        //        $orderAll['itemIds'] = $itemIds;
        //        if (! empty($orderId)) {
        //            $orderService = new OrderService();
        //            $msg = $orderService->editOrder($orderAll);
        //        }
        $this->_redirector->gotoUrl('/order/order');
    }
    public function listAction ()
    {
        $status = $this->_getParam("status");
        $orderSevice = new OrderService();
        $orders = $orderSevice->getOrders($this->view, $_POST, $status);
        $this->view->orders = $orders;
    }
    public function auditAction ()
    {
        $orderId = $this->_getParam("id");
        $order = array();
        if (! empty($orderId)) {
            $orderService = new OrderService();
            $order = $orderService->getOrderAllById($orderId);
            $items = $orderService->getOrderItemsById($orderId);
        }
        if ($order['status'] != 1) {
            $this->_redirector->gotoUrl('/order/order');
        }
        $this->view->order = $order;
        $this->view->items = $items;
    }
    public function subauditAction ()
    {
        $orderId = HttpUtil::getPostString("orderId");
        $order = array();
        $order['status'] = HttpUtil::getPostString("status");
        if (! empty($orderId)) {
            $orderService = new OrderService();
            $orderService->auditOrder($orderId, $order);
        }
        $this->_redirector->gotoUrl('/order/order');
    }
    private function getOptionList ()
    {
        $list = array();
        $list['status'] = OrderConstant::getStatusList();
        $list['shipping'] = OrderConstant::getShippingExpectList();
        $list['method'] = OrderConstant::getPaymentMethodList();
        $list['state'] = StateConstant::getStateList();
        return $list;
    }
    public function detailAction ()
    {
        $list = $this->getOptionList();
        $orderId = $this->_getParam("id");
        $order = array();
        $edit = 'false';
        $nextString = 'refundBtn';
        if (! empty($orderId)) {
            $orderService = new OrderService();
            $order = $orderService->getOrderById($orderId);
            $items = $orderService->getOrderItemsById($orderId);
        } else {
            $this->_redirector->gotoUrl('/order/order');
        }
        if($order['is_returned']==2){
             $nextString = '';
        }
        $adminService = new AdminService();
        $admins = $adminService->getAllAdmins();
        $this->view->edit = $edit;
        $this->view->nextString = $nextString;
        $this->view->order = $order;
        $this->view->items = $items;
        $this->view->status = $list['status'];
        $this->view->shipping = $list['shipping'];
        $this->view->method = $list['method'];
        $this->view->state = $list['state'];
        $this->view->admins = $admins;
    }
    public function returnAction ()
    {
        $orderService = new OrderService();
        $list = $orderService->getReturnOrders($this->view, $_POST);
        $this->view->dbGrid = $list;
    }
    public function subrefundAction ()
    {
        $orderId = HttpUtil::getPostString("orderId");
        $orderService = new OrderService();
        $order = $orderService->getOrderById($orderId);
        if ($order['is_returned'] == 1 and $order['is_delete'] == 0) {
            $refund = 0;
            //@todo  add refund logic
            $tradeComponentService = new TradeComponentService();
            $refund = 0;
            $ship_profit_total = 0;
            $order_profit_total = 0;
            switch ($order['status']) {
                case 1:
                    $newStatus = 7;
                    break;
                case 2:
                    $newStatus = 7;
                    break;
                case 3:
                    // $refund= $order["ship_profit_total"] ;
                    $newStatus = 7;
                    break;
                case 4:
                    //$refund= $order["total"] - $order["shipping_fee"] ;
                    $newStatus = 7;
                    break;
                case 5:
                    //$refund= $order["total"] - $order["shipping_fee"] ;
                    $newStatus = 7;
                    break;
                case 6:
                    $newStatus = 7;
                    break;
                case 11:
                    $newStatus = 17;
                    break;
                case 12:
                    $refund = $order["total"];
//                    $ship_profit_total = $order["ship_profit_total"];
//                    $order_profit_total = $order["order_profit_total"];
                    $tradeComponentService->refundFreezeMoney($order['agent_id'], $refund, 33, $orderId, $order['order_num'], 0);
                    $refund = 0;
                    $newStatus = 17;
                    break;
                case 13:
                    $refund = $order["total"] - $order["shipping_fee"];
                    $ship_profit_total = $order["ship_profit_total"];
                    $order_profit_total = $order["order_profit_total"];
                    $newStatus = 17;
                    break;
                case 14:
                    $refund = $order["total"] - $order["shipping_fee"];
                    $ship_profit_total = $order["ship_profit_total"];
                    $order_profit_total = $order["order_profit_total"];
                    $newStatus = 17;
                    break;
                case 15:
                    $refund = $order["total"] - $order["shipping_fee"];
                    $ship_profit_total = $order["ship_profit_total"];
                    $order_profit_total = $order["order_profit_total"];
                    $newStatus = 17;
                    break;
                case 16:
                    $newStatus = 17;
                    break;
                case 21:
                    $newStatus = 27;
                    break;
                case 22:
                    $refund = $order["total"];
//                    $ship_profit_total = $order["ship_profit_total"];
//                    $order_profit_total = $order["order_profit_total"];
                    $tradeComponentService->refundFreezeMoney($order['agent_id'], $refund, 33, $orderId, $order['order_num'], 0);
                    $refund = 0;
                    $newStatus = 27;
                    break;
                case 23:
                    $refund = $order["total"] - $order["shipping_fee"];
                    $ship_profit_total = $order["ship_profit_total"];
                    $order_profit_total = $order["order_profit_total"];
                    $newStatus = 27;
                    break;
                case 24:
                    $refund = $order["total"] - $order["shipping_fee"];
                    $ship_profit_total = $order["ship_profit_total"];
                    $order_profit_total = $order["order_profit_total"];
                    $newStatus = 27;
                    break;
                case 25:
                    $refund = $order["total"] - $order["shipping_fee"];
                    $ship_profit_total = $order["ship_profit_total"];
                    $order_profit_total = $order["order_profit_total"];
                    $newStatus = 27;
                    break;
                case 26:
                    $newStatus = 27;
                    break;
                default:
                    $newStatus = 0;
            }
            if ($refund > 0) {
                $tradeComponentService->refundCheckoutMoney($order['agent_id'], $refund, 33, $orderId, $order['order_num'], 0);
            }
            if ($ship_profit_total > 0) {
                $tradeComponentService->refundProfit($order['agent_id'], $ship_profit_total, 35, $orderId, $order['order_num'], 0);
            }
            if ($order_profit_total > 0) {
                $userIdTemp = $orderService->getAgentId($order['user_id']);                
                $tradeComponentService->refundProfit($userIdTemp, $order_profit_total, 35, $orderId, $order['order_num'], 0);
            }
            $order = array();
            $order['is_returned'] = 2;
            $order['status'] = $newStatus;
            $orderService->updateOrder($orderId, $order);
            //return inventory
            $orderService->returnInventoryByOrderId($orderId);
        }
        $this->_redirector->gotoUrl('/order/order/return');
    }
    
    
    public function operationjournalAction(){
    	$this->_helper->layout->disableLayout();
    	$orderId = HttpUtil::getPostString("orderId");
    	$orderService = new OrderService();
    	$orderJournals = $orderService->getJournalByOrderId($orderId);
    	$this->view->orderJournals = $orderJournals;
    }
    
    public function addjournalAction(){
    	$journal['order_id'] = HttpUtil::getPostString('orderId');
    	$journal['admin_id'] = HttpUtil::getPostString('operator');
    	$journal['content'] = HttpUtil::getPostString('content');
    	$journal['order_status'] = HttpUtil::getPostString('orderStatus');
    	
    	$orderService = new OrderService();
    	$orderJournalId = $orderService->addJournal($journal);
    	
    	echo json_encode($orderJournalId);
    	exit();	
    }
    
    public function deletejournalAction(){
    	$journalId = HttpUtil::getPostString('journalId');
    	$orderService = new OrderService();
    	$orderService->deleteJournal($journalId);
    	echo json_encode($journalId);
    	exit;
    }
}
